﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace FileManager
{
   public class Alarm
    {

       /// <summary>
       /// 得到报警图片保存的文件名
       /// </summary>
       /// <param name="path">保存报警图片的路径</param>
       /// <returns></returns>
       private string dir = null;
       public string GetAlarmFileName(string path, bool isFirstFrame,short horizonAngle,short verticalAngle)
       {
         
           if (isFirstFrame)
           {
               dir = path + string.Format("{0}\\{1:D2}\\{2:D2}\\", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + DateTime.Now.ToString("HH-mm-ss") + "\\";
               Directory.CreateDirectory(dir);
               SaveAlarmAngle(dir,horizonAngle, verticalAngle);
           }
               
           string fileName = dir + DateTime.Now.ToString("HH-mm-ss")+".bmp";
           return fileName;
       }

       public void SaveAlarmAngle(string dir,short horizonAngle,short verticalAngle)
       {
           FileStream fs = new FileStream(dir+DateTime.Now.ToString("HH-mm-ss")+".txt", FileMode.Create);
           StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
           sw.WriteLine(horizonAngle);
           sw.WriteLine(verticalAngle);
           sw.Close();
           fs.Close();
       }
       /// <summary>
       /// 根据路径获得报警信息目录
       /// </summary>
       /// <param name="path"></param>
       /// <returns></returns>
       public DirectoryInfo[] GetAlarmList(string path)
       {
           DirectoryInfo Dir = new DirectoryInfo(path);
           if (!Dir.Exists) return null;
           DirectoryInfo[] Dirs = Dir.GetDirectories();
           if (Dirs == null)
               return null;

           return Dirs;
       }

       /// <summary>
       /// 根据路径获得改天下面所有报警信息的目录
       /// </summary>
       /// <param name="path"></param>
       /// <returns></returns>
       public DirectoryInfo[] GetRecordDay(string path)
       {
           DirectoryInfo Dir = new DirectoryInfo(path);
           if (!Dir.Exists)
               return null;
           DirectoryInfo[] DirList = Dir.GetDirectories();
           if (DirList == null)
               return null;

           return DirList;
       }
    }
}
